package com.example.service.impl;

import com.example.mapper.precisionMeasProjectMapp;
import com.example.mapper.urgentTeardownResultMapp;
import com.example.pojo.Result;
import com.example.pojo.oilChecklistPojo;
import com.example.pojo.urgentTeardownResultPojo;
import com.example.pojo.urgentTeardownStandardPojo;
import com.example.service.urgentTeardownResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName:urgentTeardownResultImpl
 * Package:com.example.service.impl
 * Description:
 *
 * @Author：牧星苑
 * @Create 2025/10/17 18:50
 * @Version 1.0
 */
@Service
public class urgentTeardownResultImpl implements urgentTeardownResultService {
    @Autowired
    private urgentTeardownResultMapp urgentTeardownResultMapp;
    //向特急分解检测结果中插入多行
    public void insertSeveralRows(List<urgentTeardownResultPojo> pojos){
        for (int i = 0; i < pojos.size(); i++) {
            //设置创立时间
            pojos.get(i).setCreate_time(LocalDateTime.now());
            pojos.get(i).setUpdate_time(LocalDateTime.now());
        }
        urgentTeardownResultMapp.insertSeveralRows(pojos);
    }

    //查询所有特急分解检测结果
    public List<urgentTeardownResultPojo> queryAll(){
        List<urgentTeardownResultPojo> pojoList = urgentTeardownResultMapp.queryAll();
        return pojoList;
    }

    //根据分页查询特急分解检测结果
    public List<urgentTeardownResultPojo> queryByPage(Map<String, Object> map){
        Integer page =(Integer) map.get("page");
        Integer size=(Integer) map.get("size");
        Integer startRow=page*size;
        List<urgentTeardownResultPojo> urgentTeardownResultPojos=urgentTeardownResultMapp.queryByPage(startRow, size);
        return urgentTeardownResultPojos;
    }
    //查询所有特急分解检测结果总条数
    public Integer queryQuantity(){
        Integer quantity= urgentTeardownResultMapp.queryQuantity();
        return quantity;
    }

    //修改一行特急分解检测结果
    public void editOneById(urgentTeardownResultPojo pojo){
        pojo.setUpdate_time(LocalDateTime.now());
        urgentTeardownResultMapp.editOneById(pojo);
    }

    //查询特急分解检测结果一个字段为某值的数据
    public List<urgentTeardownResultPojo> queryOneField(Map<String, Object> map){
        String fieldName1 = String.valueOf(map.get("fieldName1"));
        String fieldValue1 = String.valueOf(map.get("fieldValue1"));
        List<urgentTeardownResultPojo> pojos=urgentTeardownResultMapp.queryOneField(fieldName1,fieldValue1);
        return pojos;
    }
    //查询特急分解检测结果二个字段为某值的数据
    public List<urgentTeardownResultPojo> queryTwoFields(Map<String, Object> map){
        String fieldName1 = String.valueOf(map.get("fieldName1"));
        String fieldValue1 = String.valueOf(map.get("fieldValue1"));
        String fieldName2 = String.valueOf(map.get("fieldName2"));
        String fieldValue2 = String.valueOf(map.get("fieldValue2"));
        List<urgentTeardownResultPojo> pojos=urgentTeardownResultMapp.queryTwoFields(fieldName1,fieldValue1,fieldName2,fieldValue2);
        return pojos;
    }
    //查询特急分解检测结果三个字段为某值的数据
    public List<urgentTeardownResultPojo> queryThreeFields(Map<String, Object> map){
        String fieldName1 = String.valueOf(map.get("fieldName1"));
        String fieldValue1 = String.valueOf(map.get("fieldValue1"));
        String fieldName2 = String.valueOf(map.get("fieldName2"));
        String fieldValue2 = String.valueOf(map.get("fieldValue2"));
        String fieldName3 = String.valueOf(map.get("fieldName3"));
        String fieldValue3 = String.valueOf(map.get("fieldValue3"));
        List<urgentTeardownResultPojo> pojos=urgentTeardownResultMapp.queryThreeFields(fieldName1,fieldValue1,fieldName2,fieldValue2,fieldName3,fieldValue3);
        return pojos;
    }
    //查询特急分解检测结果四个字段为某值的数据
    public List<urgentTeardownResultPojo> queryFourFields(Map<String, Object> map){
        String fieldName1 = String.valueOf(map.get("fieldName1"));
        String fieldValue1 = String.valueOf(map.get("fieldValue1"));
        String fieldName2 = String.valueOf(map.get("fieldName2"));
        String fieldValue2 = String.valueOf(map.get("fieldValue2"));
        String fieldName3 = String.valueOf(map.get("fieldName3"));
        String fieldValue3 = String.valueOf(map.get("fieldValue3"));
        String fieldName4 = String.valueOf(map.get("fieldName4"));
        String fieldValue4 = String.valueOf(map.get("fieldValue4"));
        List<urgentTeardownResultPojo> pojos=urgentTeardownResultMapp.queryFourFields(fieldName1,fieldValue1,fieldName2,fieldValue2,fieldName3,fieldValue3,fieldName4,fieldValue4);
        return pojos;
    }
    //查询特急分解检测结果五个字段为某值的数据
    public List<urgentTeardownResultPojo> queryFiveFields(Map<String, Object> map){
        String fieldName1 = String.valueOf(map.get("fieldName1"));
        String fieldValue1 = String.valueOf(map.get("fieldValue1"));
        String fieldName2 = String.valueOf(map.get("fieldName2"));
        String fieldValue2 = String.valueOf(map.get("fieldValue2"));
        String fieldName3 = String.valueOf(map.get("fieldName3"));
        String fieldValue3 = String.valueOf(map.get("fieldValue3"));
        String fieldName4 = String.valueOf(map.get("fieldName4"));
        String fieldValue4 = String.valueOf(map.get("fieldValue4"));
        String fieldName5 = String.valueOf(map.get("fieldName5"));
        String fieldValue5 = String.valueOf(map.get("fieldValue5"));
        List<urgentTeardownResultPojo> pojos=urgentTeardownResultMapp.queryFiveFields(fieldName1,fieldValue1,fieldName2,fieldValue2,fieldName3,fieldValue3,fieldName4,fieldValue4,fieldName5,fieldValue5);
        return pojos;
    }

    //上传特急分解检测结果照片
    public void editOneField(String id, String fieldName, String fieldValue){
        urgentTeardownResultMapp.editOneField(id,fieldName,fieldValue);
    }

    //修改多行特急分解检测结果(录入检测结果)
    public void uploadById(List<urgentTeardownResultPojo> pojos){
        for (urgentTeardownResultPojo pojo : pojos) {
            pojo.setUpdate_time(LocalDateTime.now());
        }
        urgentTeardownResultMapp.uploadById(pojos);
    }

    //动态查询特急分解检测结果
    public List<urgentTeardownResultPojo> queryByDynamicConditionsWithPagination(Map<String, Object> map) {
        // 获取分页参数
        Integer page = (Integer) map.get("page");
        Integer size = (Integer) map.get("size");

        // 设置默认值
        if (page == null) page = 0;
        if (size == null) size = 10;

        // 计算起始行
        Integer startRow = page * size;
        map.put("startRow", startRow);
        map.put("size", size);

        return urgentTeardownResultMapp.queryByDynamicConditionsWithPagination(map);
    }

    // 根据动态条件查询特急分解检测结果总条数
    public Integer queryByDynamicConditionsCount(Map<String, Object> map) {
        return urgentTeardownResultMapp.queryByDynamicConditionsCount(map);
    }
}
